#ifndef _dip_switch_dragonball_
#define _dip_switch_dragonball_

#include "dip_switch.h"
#include "igslib_iserial_manager.h"
#include "protocol_DragonBall.h"

namespace igslib
{
    class dipswitch_Grgn:public CDipSwitch<8>
    { 
        protected:
            static int ID;
			int LocID;
        public:

            dipswitch_Grgn()
            {
                ID++;
				LocID=ID;
                spi = nullptr;
            }

            ~dipswitch_Grgn()
			{
				if(ID>-1)
				 ID--;
			}
             void SetSPI(ISpi* value) { spi = value; diswenable();}
 
 
			 bool GetPinState(const int& inx)
            {
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
				std::bitset<8> dtmp(tmp->GetDipSwitchNV(LocID));
				state = dtmp ;	
				return state.test(inx);
            }
			
            std::vector<bool> GetPinsState()
            {
                std::vector<bool> rtn;
                for ( int i = 0 ; i < state.count() ; ++i )
                {
                    rtn.push_back(GetPinState(i));
                }
                return rtn;
            }
  
            int GetPinStateValue()
            {               
				int rtn = 0;				
				Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
				std::bitset<8> dtmp(tmp->GetDipSwitchNV(LocID));
				state = dtmp ;
                rtn = static_cast<int>(state.to_ulong());
                return rtn;
            }
			
			void diswenable() 
			{
				  Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
				  tmp-> SetupDipSwitch(LocID,1);
			}


    };
    int dipswitch_Grgn::ID = -1;
};

#endif
